package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.GameZpJiangpin;
import com.vf.admin.utils.StringEx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 大转盘奖励表
 */
@Repository
public class AppGameZpJiangpinDao extends BaseDao<GameZpJiangpin> {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 保存或者更新
     */
    public void save(GameZpJiangpin jiangpin) {
        if (jiangpin.getId() != null && jiangpin.getId() > 0) {
            this.update(jiangpin);
        } else {
            jiangpin.setId(this.add(jiangpin));
        }
    }


    //详情
    public GameZpJiangpin get(Integer id) {
        if (id == null || StringEx.isNullOrLing(id)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("SELECT * FROM game_zp_jiangpin  where 1=1");
        sbStr.append(" and id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, GameZpJiangpin.class);
    }


    //列表查询
    public List<GameZpJiangpin> findList() {
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("SELECT * FROM game_zp_jiangpin WHERE 1=1");
        sbStr.append(" and state = 1 ");
        sbStr.append(" and canyustate = 1 ");
        sbStr.append(" order by id desc ");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, GameZpJiangpin.class, null);
    }


    /**
     * 删除
     */
    public void del(int id) {
        if (id <= 0) {
            return;
        }
        String sql = "delete  from game_zp_jiangpin  where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }


    /**
     * 修改大转盘概率
     */
    public void modificationProbability(int id, String oneGl, String laterGl, String canyuState) {

        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbSql = new StringBuilder("UPDATE `game_zp_jiangpin` SET");
        sbSql.append(" `canyustate` = ?, ");
        paramList.add(canyuState);
        sbSql.append(" `onegailv` = ?, ");
        paramList.add(oneGl);
        sbSql.append(" `latergailv` = ? ");
        paramList.add(laterGl);
        sbSql.append(" WHERE `id` = ? ");
        paramList.add(id);
        String sql = sbSql.toString();
        this.update(sql, paramList);

    }

}
